/*
 * @Author: szx
 * @Date: 2022-02-25 13:28:46
 * @LastEditTime: 2022-02-25 13:49:03
 * @Description:
 * @FilePath: \leetcode\2000-2099\2075\2075.js
 */
/**
 * @param {string} encodedText
 * @param {number} rows
 * @return {string}
 */
var decodeCiphertext = function (encodedText, rows) {
    const n = encodedText.length;
    const col = Math.floor(n / rows);
    const arr = [];
    for (let i = 0; i < col; i++) {
        let r = 0;
        let c = i;
        while (r < rows && c < col) {
            arr.push(encodedText[r * col + c]);
            ++r;
            ++c;
        }
    }
    while (arr.length && arr[arr.length - 1] == ' ') arr.pop();
    return arr.join('');
};
console.log(decodeCiphertext('ch   ie   pr', 3));
